import Cookies from 'js-cookie'

// const TokenKey = 'ASH-Token'
// const RefreshTokenKey = 'ASH-RefreshToken'
// const expiresAtKey = 'ASH-ExpiresAt'
// const userInfoKey = 'ASH-UserInfo'

const prefix = 'ASH-Fixed-Assets'
const TokenKey = `${prefix}-Token`
const RefreshTokenKey = `${prefix}-RefreshToken`
const expiresAtKey = `${prefix}-ExpiresAt`
const userInfoKey = `${prefix}-UserInfo`

//取值
export function getToken() {
  return Cookies.get(TokenKey)
}
export function getRefreshToken() {
  return Cookies.get(RefreshTokenKey)
}
export function getExpires() {
  return Cookies.get(expiresAtKey)
}
export function getUserInfo() {
  return Cookies.get(userInfoKey)
}

//赋值
export function setToken(token) {
  return Cookies.set(TokenKey, token)
}
export function setRefreshToken(rToken) {
  return Cookies.set(RefreshTokenKey, rToken)
}
export function setExpires(expiresAt) {
  return Cookies.set(expiresAtKey, expiresAt)
}
export function setUserInfo(userInfo) {
  // cookie存储对象时，必须转化为JSON字符串，否则读取不到对象里的属性值
  return Cookies.set(userInfoKey, userInfo)
}

//删除
export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function removeRefreshToken() {
  return Cookies.remove(RefreshTokenKey)
}
export function removeExpires() {
  return Cookies.remove(expiresAtKey)
}
export function removeUserInfo() {
  return Cookies.remove(userInfoKey)
}
